package com.springboot.springbootlogindemo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.springboot.springbootlogindemo.domain.MusicCollection;
import com.springboot.springbootlogindemo.domain.Song;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;


@Mapper
public interface MusicCollectionMapper extends BaseMapper<MusicCollection> {

    /**
     * 定义双表查询sql语句，这里的意思就是根据歌单id在mc表中查找，然后根据查到的songId和song表的songId匹配，将匹配的song信息存入list
     * @param songListId
     * @return
     */
    @Select("SELECT song.*, mc.song_list_id FROM song song " +
            "JOIN music_collection mc ON song.id = mc.song_id " +
            "WHERE mc.song_list_id = #{songListId}")
    List<Song> findSongsFromSongList(Long songListId);

}
